/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ai.loa.framework.view;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.imageio.ImageIO;


/**
 *
 * @author root
 */
public class LOAImageFactory {

    public static final String  IMG_BOARD="board.png",
                                IMG_PLAYER_1="player1.png",
                                IMG_PLAYER_2="player2.png",
                                IMG_CELL_HIGHLIGHT="highlight.png",
                                IMG_EMPTY="empty.png";
                                
    Map<String,BufferedImage> images;

    private Properties config;

    public LOAImageFactory(String skinName) throws IOException{
        images=new HashMap<String,BufferedImage>();
        String basePath="skins/"+skinName+"/";

        config=new Properties();
        config.load(new FileInputStream(basePath+"LOA_skin.properties"));

        images.put(IMG_BOARD,ImageIO.read(new File(basePath+IMG_BOARD)));
        images.put(IMG_PLAYER_1,ImageIO.read(new File(basePath+IMG_PLAYER_1)));
        images.put(IMG_PLAYER_2,ImageIO.read(new File(basePath+IMG_PLAYER_2)));
        images.put(IMG_CELL_HIGHLIGHT,ImageIO.read(new File(basePath+IMG_CELL_HIGHLIGHT)));

        images.put(IMG_EMPTY,ImageIO.read(new File(basePath+IMG_EMPTY)));

    }

    public BufferedImage getImage(String name){
        return images.get(name);
    }

    public BufferedImage getNewImage(String name){
        BufferedImage img=getImage(name);
        BufferedImage res=new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_4BYTE_ABGR);
        res.getGraphics().drawImage(img, 0, 0, null);
        return res;
    }

    public int getBaseX(){
        return Integer.parseInt(config.getProperty("base_x"));
    }

    public int getBaseY(){
        return Integer.parseInt(config.getProperty("base_y"));
    }

    public int getCellWidth(){
        return Integer.parseInt(config.getProperty("cell_width"));
    }

    public int getCellHeight(){
        return Integer.parseInt(config.getProperty("cell_height"));
    }

}
